package org.zpmis.domain.contract.vo;

import lombok.Data;
import org.zpmis.domain.contract.model.ContractBill;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

@Data
public class ContractBillListVo {
    private Long id;

    /**
     * 合同id
     */
    private Long contractId;

    /**
     * 账单编号
     */
    private String code;

    /**
     * 账单名称
     */
    private String name;

    /**
     * 账单金额
     */
    private String amount;

    /**
     * 预计收款日期
     */
    private String expectTime;

    /**
     * 最迟收款日期
     */
    private String deadlineTime;

    /**
     * 实际收款日期
     */
    private String actualTime;

    /**
     * 收款人id
     */
    private Long payeeId;

    /**
     * 收款人
     */
    private String payee;

    /**
     * 创建人id
     */
    private Long createId;

    /**
     * 创建人
     */
    private String createPerson;

    /**
     * 创建时间
     */
    private String createTime;

    /**
     * 账单状态 0 未收款 1 已收款
     */
    private Integer status;

    public ContractBillListVo(ContractBill contractBill) {
        this.id = contractBill.getId();
        this.contractId = contractBill.getContractId();
        this.code = contractBill.getCode();
        this.name = contractBill.getName();
        this.amount = String.valueOf(contractBill.getAmount());
        this.expectTime = contractBill.getExpectTime() == null ? "" : LocalDateTime.ofInstant(Instant.ofEpochMilli(contractBill.getExpectTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        this.deadlineTime = contractBill.getDeadlineTime() == null ? "" : LocalDateTime.ofInstant(Instant.ofEpochMilli(contractBill.getDeadlineTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        this.actualTime = contractBill.getActualTime() == null ? "" : LocalDateTime.ofInstant(Instant.ofEpochMilli(contractBill.getActualTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        this.payeeId = contractBill.getPayeeId();
        this.payee = contractBill.getPayee();
        this.createId = contractBill.getCreateId();
        this.createPerson = contractBill.getCreatePerson();
        this.createTime = contractBill.getCreateTime() == null ? "" : LocalDateTime.ofInstant(Instant.ofEpochMilli(contractBill.getCreateTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        this.status = contractBill.getStatus();
    }
}